package yang.yu.sunny.service.impl;

import yang.yu.sunny.EventBus;
import yang.yu.sunny.domain.product.Product;
import yang.yu.sunny.domain.product.ProductNameChangedEvent;
import yang.yu.sunny.infra.persistence.product.ProductCategoryMapper;
import yang.yu.sunny.infra.persistence.product.ProductMapper;
import yang.yu.sunny.service.ProductService;

import javax.inject.Inject;

/**
 * Created by yyang on 16/4/12.
 */
public class ProductServiceImpl implements ProductService {

    @Inject
    private ProductMapper productMapper;

    @Inject
    private ProductCategoryMapper categoryMapper;

    @Inject
    private EventBus eventBus;

    @Override
    public void changeProductName(Long productId, String newName) {
        Product product = productMapper.get(productId);
        String oldName = product.getName();
        product.setName(newName);
        productMapper.update(product);
        eventBus.post(new ProductNameChangedEvent(productId, oldName, newName));
    }
}
